/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package survey_dlt;

import dbhandler.DBConnection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Swami
 */
public class comlst {
    
    int cid,bk,ht;
    float cpi;
    public ArrayList viewcom() throws SQLException
    {
       String Query;
    Query="Select * from tbl_committee;";
    
    DBConnection db= new DBConnection();
    ArrayList<comupd> comarr=new ArrayList<comupd>();
    ResultSet rs;
    
    db.connect();
    try{
        rs=db.customQuery(Query);
        
        while(rs.next())
        {
            comupd comt=new comupd();
            comt.setCom_id(Integer.parseInt(rs.getString(1)));
            comt.setCom_name(rs.getString(2));
            
            comarr.add(comt);
            
        }
        
    }catch(SQLException e){
        e.printStackTrace();
    }
        
            
    
    
    
    return comarr;
    } 
        
    
    
        public ArrayList eligibilitychk() throws SQLException
    {
    String Query;
    
    Query="Select * from tbl_eligibility;";
    
    DBConnection db= new DBConnection();
    ArrayList<eligibility> eligiblearr=new ArrayList<eligibility>();
    ResultSet rs;
    
    db.connect();
    try{
        rs=db.customQuery(Query);
        
        while(rs.next())
        {
            eligibility eligible=new eligibility();
            eligible.getCom_id();
            eligible.getCpi();
            eligible.getBacklog();
            eligiblearr.add(eligible);
            
        }
        
    }catch(SQLException e){
        e.printStackTrace();
    }
        

    return eligiblearr;
 }
    
    public boolean addeligiblity(eligibility eligbl) throws SQLException
    {
    String Query;
    
    Query="INSERT INTO `tbl_eligibility`(`com_id`, `cpi`, `backlog`) VALUES ("+eligbl.getCom_id()+","+eligbl.getCpi()+","+eligbl.getBacklog()+");";
    
    DBConnection db= new DBConnection();
    ArrayList<eligibility> eligiblearr=new ArrayList<eligibility>();
    ResultSet rs;
    
    db.connect();
    try{
        db.executeQuery(Query);
        
    }
    catch(SQLException e){
        e.printStackTrace();
    }
        
    
    return true;
    }

public void update(String cid, String cpi, String bk, String ht) {
    DBConnection db= new DBConnection();
           db.connect();
           boolean rs2;
                
    try
       {
           //this.qid=id;
           this.cid=Integer.parseInt(cid);
                     this.cpi=Float.parseFloat(cpi);
           this.bk=Integer.parseInt(bk);
           this.ht=Integer.parseInt(ht);
 
           rs2=db.executeQuery("update tbl_eligibility set com_id="+this.cid+",cpi='"+this.cpi+"',backlog="+this.bk+",hostel="+this.ht+" where com_id="+this.cid+"");
       }
 catch (SQLException ex) {
       
 }
 db.disconnect();
}


 public ArrayList viewelg(String e)throws SQLException
    
 {
        String Query;
    int ci=Integer.parseInt(e);
    Query="Select * from tbl_eligibility where com_id="+ci;
    
    DBConnection db= new DBConnection();
    ArrayList<eligibility> comarr=new ArrayList<eligibility>();
    ResultSet rs;
    
    db.connect();
    try{
        rs=db.customQuery(Query);
        
        while(rs.next())
        {
            eligibility comt=new eligibility();
            comt.setCom_id(Integer.parseInt(rs.getString(1)));
            comt.setBacklog(Integer.parseInt(rs.getString(3)));
            comt.setCpi(Float.parseFloat(rs.getString(2)));
           comt.setHostel(Integer.parseInt(rs.getString(4))); 
            comarr.add(comt);
         }
    }
     catch(SQLException ex)
     {
     ex.printStackTrace();
     }
return comarr; 
 }

    
  public static void main(String [] args){
        try{
            /*eligibilitycheck el=new eligibilitycheck();
            eligibility e=new eligibility();
            e.setBacklog(0);
            e.setCom_id(1);
            e.setCpi(8);
            el.addeligiblity(e);
            */
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
    